<template>
    <view v-if=" json.orderStatus == 15 || json.orderStatus == 20 ">

        <view class="commonFoot">
            <view class="foot-btn-box fixed">
                <!-- v-if=" json.orderStatus == 15 " -->
                <view class="foot-btn" @click="goReceiving" v-if=" json.orderStatus == 15 ">
                    <text>点击开始送货</text>
                </view>
                <!-- v-if=" json.orderStatus == 20 " -->
                <view class="foot-btn green" @click="goFinish" v-if=" json.orderStatus == 20 ">
                    <text>点击送货完成</text>
                </view>
            </view>
        </view>

        <!-- 验证码 -->
        <VerifyCode :isShow.sync="showCode" @finish="finishInputCode" />

    </view>
</template>
<script>

import Process from '../../utils/process'
import VerifyCode from '../VerifyCode'

export default {
    props: ['json', 'hasBeforeReceive', 'orderType'],
    components: { VerifyCode },
    data () {
        return {

            showCode: false,
        }
    },


    mounted () {

    },
    methods: {
        //开始送货
        goReceiving () {

            // 如果提供执行
            if (this.hasBeforeReceive) {

                this.$emit('goReceivingBefore', () => {

                    this.receiveFunc()
                })

            }
            // 否侧执行其他
            else {
                this.receiveFunc()
            }



        },
        //开始配货请求
        receiveFunc () {

            // console.log('开始配货了99999999999999999999')
            let that = this

            uni.showModal({
                title: '温馨提示',
                content: '确定是否开始配送？',
                confirmText: "开始配送",
                cancelText: "取消",
                success: function (res) {
                    if (res.confirm) {

                        // console.log('配送开始了。。。。。。。。。。。。。。。。。。。。。。。。。。。')
                        if (that.orderType == 'kd') {

                            Process.deliveryExpressReceiving(that.json.id)
                                .then(res => {

                                    // console.log('开始配货了', res)
                                    uni.showToast({ title: '开始配送' })

                                    that.$emit('finish')

                                })

                            return

                        }

                        Process.deliveryReceiving(that.json.id)
                            .then(res => {

                                uni.showToast({ title: '开始配送' })
                                // console.log('开始配货了', res)

                                that.$emit('finish')

                            })

                    }
                }
            })


        },
        //点击完成  弹框
        goFinish () {

            this.showCode = true

        },

        finishInputCode (code) {

            // console.log('喀喀喀',code)

            if (code) {

                Process.deliveryFinish(this.json.id, code)
                    .then(res => {

                        console.log('配货完成了', res)

                        uni.showToast({ title: '配送完成' })

                        this.$emit('finish')

                    })
            }

        },

    }
}
</script>
<style lang="scss" scoped>
</style>